<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h2>位运算符</h2>
    <ul>
        <li>&：位与运算，11为1,10为0,00为0</li>
        <li>|：位或运算，11为1,10为1,00为0</li>
        <li>^：位异或运算，相等为0，不等为1</li>
        <li>~：对位求返 1为0，0为1</li>
        <li>&lt;&lt;：为左移运算</li>
        <li>>>：位右移运算</li>
    </ul>
    <script>
        let a = 2; // 10
        let b = 3; // 11

        let c = a & b; // 10
        console.log("c = ",c);

        c = a | b;
        console.log("c = ",c);

        b = 3;  // 11
        c = a ^ b;
        console.log("c = ",c);

        a = 2; // 10
        a = ~a; // 01
        console.log("a = ",a);

        // 为左移是最快速的求出n的2次方方法
        a = 2;
        let e = a << 1;
        console.log("e = ",e);

        a = 8; // 计算a/4最快方法：
        a = a >> 2;
        console.log("a = ",a);

        // 计算机计算平均数最快方法
        let byte = 1;
        let kb = byte << 10;
        let mb = kb << 10;
        let gb = mb << 10;
        console.log(gb)



    </script>
</body>
</html>